package com.axonactive.managedbean;

import com.axonactive.entity.Book;
import com.axonactive.service.BookService;

import javax.enterprise.context.RequestScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import javax.persistence.PersistenceContext;
import java.util.List;

@Named
@RequestScoped
public class BookBean {
    private String bookTitle;

    @PersistenceContext
    private BookService bookService;

    public void saveBook(ActionEvent event) {
        System.out.println("Add method called.");
        Book newBook = new Book();
        newBook.setTitle(bookTitle);
        bookService.add(newBook);
    }

    public List<Book> getListBooks() {
        return bookService.getBooks();
    }

    public String getBookTitle() {
        return bookTitle;
    }

    public void setBookTitle(String bookTitle) {
        this.bookTitle = bookTitle;
    }
}
